﻿using App2.Controls;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Reflection;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace App2
{
    public class ViewModel : BindableBase
    {
        public ViewModel()
        {
            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            { /* TODO */ }
        }

        // public method
        public void RefreshData() { this.RefreshInfo = string.Format("Data Refreshed {0}", DateTime.Now); }

        string _RefreshInfo = default(string);
        public string RefreshInfo { get { return _RefreshInfo; } set { SetProperty(ref _RefreshInfo, value); } }

        // ChangeColorCommand
        DelegateCommand<String> m_ChangeColorCommand = null;
        public DelegateCommand<String> ChangeColorCommand
        {
            get
            {
                if (m_ChangeColorCommand != null)
                    return m_ChangeColorCommand;
                m_ChangeColorCommand = new DelegateCommand<String>(ChangeColorCommandExecute, (o) => true);
                this.PropertyChanged += (s, e) => m_ChangeColorCommand.RaiseCanExecuteChanged();
                return m_ChangeColorCommand;
            }
        }
        private void ChangeColorCommandExecute(String o) { this.Color = new SolidColorBrush((Color)typeof(Colors).GetRuntimeProperty(o.ToString()).GetValue(null)); }

        SolidColorBrush _Color = new SolidColorBrush(Colors.White);
        public SolidColorBrush Color { get { return _Color; } set { SetProperty(ref _Color, value); } }

    }

    public abstract class BindableBase : System.ComponentModel.INotifyPropertyChanged
    {

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
        protected void SetProperty<T>(ref T storage, T value, [System.Runtime.CompilerServices.CallerMemberName] String propertyName = null)
        {
            if (!object.Equals(storage, value))
            {
                storage = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
            }
        }
        protected void RaisePropertyChanged([System.Runtime.CompilerServices.CallerMemberName] String propertyName = null)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }
    }
}
